//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.zxbit.flash.utils;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import java.text.MessageFormat;

public class ToastUtils {
    private static Toast toast;

    public ToastUtils() {
    }

    public static void showToastOnce(Activity activity, final String content) {
        if (activity != null) {
            final Context context = activity.getApplication();
            if (toast == null) {
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        ToastUtils.toast = Toast.makeText(context, content, 0);
                    }
                });
            } else {
                toast.setText(content);
            }

            toast.show();
        }
    }

    private static void show(Activity activity, final int resId, final int duration) {
        if (activity != null) {
            final Context context = activity.getApplication();
            activity.runOnUiThread(new Runnable() {
                public void run() {
                    Toast.makeText(context, resId, duration).show();
                }
            });
        }
    }

    private static void show(Activity activity, final String message, final int duration) {
        if (activity != null) {
            if (!TextUtils.isEmpty(message)) {
                final Context context = activity.getApplication();
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(context, message, duration).show();
                    }
                });
            }
        }
    }

    public static void showLong(Activity activity, int resId) {
        show(activity, resId, 1);
    }

    public static void showShort(Activity activity, int resId) {
        show(activity, resId, 0);
    }

    public static void showLong(Activity activity, String message) {
        show(activity, message, 1);
    }

    public static void showShort(Activity activity, String message) {
        show(activity, message, 0);
    }

    public static void showLong(Activity activity, String message, Object... args) {
        String formatted = MessageFormat.format(message, args);
        show(activity, formatted, 1);
    }

    public static void showShort(Activity activity, String message, Object... args) {
        String formatted = MessageFormat.format(message, args);
        show(activity, formatted, 0);
    }

    public static void showLong(Activity activity, int resId, Object... args) {
        if (activity != null) {
            String message = activity.getString(resId);
            showLong(activity, message, args);
        }
    }

    public static void showShort(Activity activity, int resId, Object... args) {
        if (activity != null) {
            String message = activity.getString(resId);
            showShort(activity, message, args);
        }
    }
}
